package models

import (
	"github.com/astaxie/beego/orm"
)

type Theme struct {
	Id       int64 `orm:"pk;auto"`  // 项目ID
	ImageId  int64 `orm:"size(11)"` // 项目父级ID
	UseState int64 `orm:"size(1)"`  //删除
}

func (m *Theme) TableName() string {
	return "theme"
}

// 获取全部用户
func (m *Theme) GetAllTheme() []*Theme {
	list := make([]*Theme, 0)
	_, _ = m.Query().All(&list)
	return list
}

func (m *Theme) GetThemeLists() []map[string]interface{} {
	list := make([]*Theme, 0)
	_, _ = m.Query().All(&list)
	resTree := make([]map[string]interface{}, 0)
	for _, citem := range list {
		cres := ThemeJson(citem)
		resTree = append(resTree, cres)
	}
	return resTree
}

// 查询方法
func (m *Theme) Query() orm.QuerySeter {
	return orm.NewOrm().QueryTable(m)
}

// 添加用户
func (m *Theme) Insert() error {
	_, err := orm.NewOrm().Insert(m)
	return err
}

// 删除用户
func (m *Theme) Delete() error {
	_, err := orm.NewOrm().Delete(m)
	return err
}

// 修改用户信息
func (m *Theme) Update(fields ...string) error {
	_, err := orm.NewOrm().Update(m, fields...)
	return err
}
func (m *Theme) Read(fields ...string) (*Theme, error) {
	err := orm.NewOrm().Read(m, fields...)
	return m, err
}

// ReadForUpdate
func (m *Theme) ReadForUpdate(fields ...string) (*Theme, error) {
	err := orm.NewOrm().ReadForUpdate(m, fields...)
	return m, err
}

// 通过ID查询
// 通过email或者单个用户信息
func (m *Theme) GetThemeById(id int64) (*Theme, error) {
	err := m.Query().Filter("id", id).One(m)
	return m, err
}
